package com.wangtianxiang.sxp.common.dto;

import java.io.Serializable;
import java.util.List;

public class PageData<T> implements Serializable{
	private static final long serialVersionUID = -586593137501831576L;
	/**当前页*/
	private long page;
	/**每页记录数*/
	private long pageSize;
	/**总记录数*/
	private long totalRecords;
	/**总共多少页*/
	private long totalPages;
	/**结果列表*/
	private List<T> resultList;
	public PageData(){
		
	}
	public PageData(long page , long pageSize, long totalRecords, List<T> resultList){
		setPage(page);
		setPageSize(pageSize);
		setTotalRecords(totalRecords);
		setResultList(resultList);
	}
	public long getPage() {
		return page;
	}

	public void setPage(long page) {
		this.page = page;
	}

	public long getPageSize() {
		return pageSize;
	}

	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
	}

	public long getTotalRecords() {
		return totalRecords;
	}

	public void setTotalRecords(long totalRecords) {
		this.totalRecords = totalRecords;
		int pages = (int) (totalRecords / this.pageSize);
		if(pages * this.pageSize < totalRecords ){
			setTotalPages(pages+1);
		}else {
			setTotalPages(pages);
		} 
		
	}

	public long getTotalPages() {
		return this.totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	
	public List<T> getResultList() {
		return resultList;
	}
	
	public void setResultList(List<T> resultList) {
		this.resultList = resultList;
	}
	@Override
	public String toString() {
		return "PageData [page=" + page + ", pageSize=" + pageSize + ", totalRecords=" + totalRecords + ", totalPages="
				+ totalPages + ", resultList=" + resultList + "]";
	}
	
	

}
